#include "ppcomment.h"

namespace losor
{
	ppcomment::ppcomment( ppobject *parent ):
		ppobject( "comment", parent )
	{
		// TODO:
	}
		
	ppcomment::~ppcomment()
	{
		// TODO:
	}
	
	long ppcomment::parser( code &_code )
	{
		int line = 0;
		unsigned char* ptr = (unsigned char*)_code.str;

		if( ptr[1] == '/' && ptr[0] == '/' )
		{
			ptr += 2;
			while( *ptr != '\n' && *ptr != 0 ) 
				++ptr;
			m_caption = string( _code.str, ptr-_code.str );
			m_line = _code.line;
			_code.str = ptr;
			return 0;
		}
		else if( ptr[1] == '*' && ptr[0] == '/' )
		{
			ptr += 2;
			while( *ptr != 0 && (ptr[0] != '*' || ptr[1] != '/') ) 
			{
				if( *ptr == '\n' )
					++line;
				++ptr;
			}
			if( *ptr != 0 )
				ptr += 2;
			m_caption = string( _code.str, ptr-_code.str );
			m_line = _code.line + line;
			_code.str = ptr;
			_code.line += line;
			return 0;
		}
		return -1;
	}
}
